import React from 'react';
import { ActivityIndicator, FlatList, Image, RefreshControl, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { Icon } from 'react-native-elements';
// import console = require('console');
interface ClassRecord {
	student_no: string;
	student_name: string;
}

export default function tpl(a: <T>(action: string, ...args: unknown[]) => ((...args: unknown[]) => void), s: (...class_names: string[]) => {}, d: (d: string) => string | unknown[]) {
	const arr = d('d') as ClassRecord[];
	// if (arr && arr.length > 0) {
	// const c = d('c');
	const page_no = Number(d('page_no'));
	const page_size = 20;
	// const new_len = Number(d('new_len'));
	const grade = d('grade');
	const class_name = d('class_name');
	const ys = Number(d('ys'));
	// console.log('ys', ys);
	// if (c === '0') {
	return (<View>
		<View>
			<View style={{ flexDirection: 'row', alignItems: 'center' }}>
				<TextInput style={{ borderColor: '#ddd', borderWidth: 1, margin: 10, borderRadius: 5, height: 40, width: 300 }} placeholder="请输入关键字" onChangeText={a('a005')}></TextInput>
				<TouchableOpacity onPress={a('a003')}>
					<Image source={require('../../imgs/sousuo.jpg')}></Image>
				</TouchableOpacity>
			</View>
			{(() => {
				if (arr !== undefined) {
					return (
						<View style={{ paddingBottom: 180 }}>
							<FlatList style={{ paddingBottom: 40 }} refreshControl={
								<RefreshControl
									onRefresh={a('a003')}
									colors={['#ff0000']}
									enabled={true}
									progressBackgroundColor="#ffffff"
									refreshing={false}

								/>
							}
								onEndReached={a('a002', page_no + 1)}
								onEndReachedThreshold={0.1}
								data={arr} renderItem={({ item, index }) => {
									return (<View>
										<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 10, borderColor: '#ddd', borderBottomWidth: 1 }}>
											<View style={{ flexDirection: 'row' }}>
												<Text>班级：</Text><Text>{grade}{class_name}</Text>
											</View>
											<View>
												<Text>{item.student_name}</Text>
											</View>
											<View>
												<TouchableOpacity onPress={a('a004', item.student_no)}>
													<Icon name="chevron-right" color="#999999" size={30}></Icon>
												</TouchableOpacity>
											</View>
										</View>
										{(() => {
											const len = arr.length;
											if (len === index + 1 && len > page_size - 1) {
												if (page_no < ys) {
													return (
														<View style={s('footer')}>
															<ActivityIndicator />
															<Text>正在加载更多数据...</Text>
														</View>
													);
												}
											}

											if (len === index + 1 && index < page_size - 1 && len >= 9) {
												return (
													<View style={{ height: 30, backgroundColor: '#f4f4f4' }}>
														<Text style={{ color: '#999999', fontSize: 14, marginTop: 5, marginBottom: 5, textAlign: 'center' }}>
															没有更多数据了
											</Text>
													</View>
												);
											} else if (len === index + 1 && index === page_size - 1) {
												if (page_no === ys) {
													return (
														<View style={{ height: 30, backgroundColor: '#f4f4f4' }}>
															<Text style={{ color: '#999999', fontSize: 14, marginTop: 5, marginBottom: 5, textAlign: 'center' }}>
																没有更多数据了
												</Text>
														</View>
													);
												}
											}



										})()}
									</View>);
								}} />{arr.length === 0 &&
									<View style={s('page')}>
										<Image source={require('../../imgs/wushuju.png')} style={{ width: 80, height: 80 }} />
										<Text style={{ fontSize: 20 }}>没有符合当前筛选条件的数据</Text>
									</View>
							}




							{/* ---------------------------------------------- */}
							{/* <View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 10, borderColor: '#ddd', borderBottomWidth: 1 }}>
						<View style={{ flexDirection: 'row' }}>
							<Text>班级：</Text><Text>一年级一班</Text>
						</View>
						<View>
							<Text>赵四</Text>
						</View>
						<View>
							<Icon name="chevron-right" color="#999999" size={30}></Icon>
						</View>
					</View>
					<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 10, borderColor: '#ddd', borderBottomWidth: 1 }}>
						<View style={{ flexDirection: 'row' }}>
							<Text>班级：</Text><Text>一年级一班</Text>
						</View>
						<View>
							<Text>王五</Text>
						</View>
						<View>
							<Icon name="chevron-right" color="#999999" size={30}></Icon>
						</View>
					</View> */}
							{/* ---------------------------------------------- */}


						</View>);
				} else {
					return (
						<View style={s('footer1')}>
							<ActivityIndicator
								animating={true}
								color='blue'
								size="large"
							/>
						</View>
					);
				}
			})()}
		</View>
	</View >);
	// } else {
	// 	return (<View><View style={{ flexDirection: 'row', alignItems: 'center' }}>
	// 		<TextInput style={{ borderColor: '#ddd', borderWidth: 1, margin: 10, borderRadius: 5, height: 40, width: 300 }} placeholder="请输入关键字" onChangeText={a('a005')}></TextInput>
	// 		<TouchableOpacity onPress={a('a003')}>
	// 			<Image source={require('../../imgs/sousuo.jpg')}></Image>
	// 		</TouchableOpacity>
	// 	</View>
	// 		<View style={{ height: 30, backgroundColor: '#f4f4f4' }}>
	// 			<Text style={{ color: '#999999', fontSize: 14, marginTop: 5, marginBottom: 5, textAlign: 'center' }}>
	// 				没有更多数据了
	// 											</Text>
	// 		</View>
	// 	</View>);
	// }
}
// }

